package main.java.br.com.projeto.domain.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import main.java.br.com.projeto.domain.entity.Perfil;

public class DaoPerfil extends Dao<Perfil> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4176678008616267610L;

	public DaoPerfil() {
		super(Perfil.class);
	}

	public List<Perfil> listByFilter(Long id, String filter) {
		String hql = "select perfil from Perfil perfil "
				+ "where (lower(perfil.perfil) like '%' || lower ( cast(:filter as string) ) || '%' or :filter = null) "
				+ "and (perfil.id = :id or :id = 0)";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("filter", filter);
		parameters.put("id", id);

		return this.findOneResult(hql, parameters);
	}
	
	public List<Perfil> listByName(String filter) {
		String hql = "select perfil from Perfil perfil "
				+ "where (lower(perfil.perfil) like '%' || lower ( cast(:filter as string) ) || '%' or :filter = null) ";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("filter", filter);

		return this.findOneResult(hql, parameters);
	}
	
	public List<Perfil> listPerfilByQuery( String query )
	{
		String hql = "select perfil from Perfil perfil "
				+ "where (lower(perfil.perfil) like '%' || lower ( cast(:query as string) ) || '%') ";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("query", query);

		return this.findOneResult(hql, parameters);
	}
}
